from readFile import read_json, read_json_one_row
from predictOneDict import predict_one_dict
import numpy as np


def predict_all_dict(path, length, width, thresold=0, n_days=5):
    all_data, count_data = read_json(path, length, width)
    predict_results = np.zeros((all_data.shape[0], all_data.shape[1], n_days))
    cnt = 0

    for m in range(all_data.shape[0]):
        for n in range(all_data.shape[1]):
            if count_data[m][n] > thresold:
                dataset = all_data[m][n]
                dataset = dataset.reshape([-1, 1])
                print(dataset.shape)
                res = predict_one_dict(dataset, dataset, n_days)

                predict_results[m][n] = res
                cnt = cnt + 1
    print(cnt)
    return predict_results


def predict_all_dict_one_row(path, row, width, thresold=100, n_days=5):
    """

    :param path: 文件路径
    :param row: 行向量
    :param width: 数据数量
    :param thresold: 阈值
    :param n_days: 预测未来几天
    :return:
    """
    all_data, count_data = read_json_one_row(path, row, width)
    predict_results = np.zeros((all_data.shape[0], all_data.shape[1], n_days))
    cnt = 0

    for m in range(all_data.shape[0]):
        for n in range(all_data.shape[1]):

            # 设置阈值  thresold
            if count_data[m][n] > thresold:
                dataset = all_data[m][n]
                dataset = dataset.reshape([-1, 1])
                res = predict_one_dict(dataset, dataset, n_days)
                predict_results[m][n] = res
                cnt = cnt + 1
            else:
                predict_results[m][n] = 0
    print(cnt)
    return predict_results
